Skip to content

Silence datetime accessor deprecation warnings#11270

Open
spencerkclark wants to merge 4 commits intopydata:mainfrom
spencerkclark:fix/pandas-deprecation-warnings
Open

Silence datetime accessor deprecation warnings#11270
spencerkclark wants to merge 4 commits intopydata:mainfrom
spencerkclark:fix/pandas-deprecation-warnings

Conversation

@spencerkclark
Copy link
Copy Markdown
Member

@spencerkclark spencerkclark commented Mar 30, 2026

This PR silences datetime-related warnings surfaced in the latest upstream build. It also follows pandas in deprecating redundant accessor names, and adds day_of_week and day_of_year accessors to CFTimeIndex.

@spencerkclark spencerkclark force-pushed the fix/pandas-deprecation-warnings branch from b1580db to 3d4c471 Compare April 4, 2026 16:55
@spencerkclark spencerkclark force-pushed the fix/pandas-deprecation-warnings branch 3 times, most recently from f833723 to d676fbf Compare April 4, 2026 17:33
@github-actions github-actions bot added topic-indexing CI Continuous Integration tools Automation Github bots, testing workflows, release automation labels Apr 4, 2026
@spencerkclark spencerkclark force-pushed the fix/pandas-deprecation-warnings branch from 37dc249 to 16c0b3a Compare April 4, 2026 19:39
@spencerkclark spencerkclark added run-upstream Run upstream CI and removed topic-indexing CI Continuous Integration tools Automation Github bots, testing workflows, release automation labels Apr 4, 2026
@spencerkclark spencerkclark marked this pull request as ready for review April 5, 2026 17:27
@dcherian
Copy link
Copy Markdown
Contributor

dcherian commented Apr 6, 2026

Do we really need to deprecate these? They've been around for so long, perhaps we should just keep both names.

@spencerkclark
Copy link
Copy Markdown
Member Author

Yeah, I don't have a particularly strong opinion. I'm fine with maintaining the other aliases. I'll revert those changes when I get a chance.

@github-actions github-actions bot added topic-backends topic-plotting topic-zarr Related to zarr storage library Automation Github bots, testing workflows, release automation topic-hypothesis Strategies or tests using the hypothesis library io labels Apr 11, 2026
@spencerkclark spencerkclark force-pushed the fix/pandas-deprecation-warnings branch from db9fad4 to 30eb968 Compare April 11, 2026 11:34
@spencerkclark spencerkclark force-pushed the fix/pandas-deprecation-warnings branch from 30eb968 to bd99e04 Compare April 11, 2026 11:38

weekday = dayofweek
dayofweek = day_of_week
weekday = day_of_week
Copy link
Copy Markdown
Member Author

@spencerkclark spencerkclark Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An awkward aspect of this approach for adding datetime accessor aliases, which was present before this PR, is that the name of the resulting DataArray is inconsistent with the name of the alias, e.g. in the current version of xarray:

>>> times = xr.date_range("2000", periods=10)
>>> xr.DataArray(times, dims=["time"]).dt.weekday
<xarray.DataArray 'dayofweek' (time: 10)> Size: 80B
array([5, 6, 0, 1, 2, 3, 4, 5, 6, 0])
Coordinates:
  * time     (time) datetime64[ns] 80B 2000-01-01 2000-01-02 ... 2000-01-10

A current consequence of this in this PR is that the name of these DataArrays will change:

>>> xr.DataArray(times, dims=["time"]).dt.weekday
<xarray.DataArray 'day_of_week' (time: 10)> Size: 80B
array([5, 6, 0, 1, 2, 3, 4, 5, 6, 0])
Coordinates:
  * time     (time) datetime64[ns] 80B 2000-01-01 2000-01-02 ... 2000-01-10

We could rename to always match the old names if we want to be as conservative as possible, but it feels more intuitive for the name of the DataArray to match the name of the accessor attribute. Should we address this as part of this PR as well?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these properties are just one line of code, it doesn't hurt to add the aliases as "real" properties back. This also allows us to depreciate it as well (do we want to?).

Copy link
Copy Markdown
Member Author

@spencerkclark spencerkclark Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my second suggestion would involve defining the aliases as their own independent properties to give us control over the name of the resulting DataArrays. My feeling is that we could consider the name mismatch a "bug" which we could fix without a deprecation cycle, but I am open to opinions from others.

@spencerkclark spencerkclark force-pushed the fix/pandas-deprecation-warnings branch from 7067a40 to 7039d7b Compare April 11, 2026 11:54
@spencerkclark spencerkclark removed topic-backends topic-plotting topic-zarr Related to zarr storage library Automation Github bots, testing workflows, release automation topic-hypothesis Strategies or tests using the hypothesis library io labels Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⚠️ Nightly upstream-dev CI failed ⚠️

4 participants